<extend name="_Layout/main"/>

<block name="main">
    <div class="row builder builder-form-box">
        <div class="col-xs-12 builder-form-container">
            <form action="__SELF__" method="post" class="form builder-form">
                <ul class="nav-tabs nav" style="margin-bottom: 20px;">
                    <li class="active"><a href="#tab1" data-toggle="tab">部门信息</a></li>
                    <neq name="info.id" value="1"><li><a href="#tab2" data-toggle="tab">系统权限</a></li></neq>
                    <neq name="info.id" value="1"><li><a href="#tab3" data-toggle="tab">分类权限</a></li></neq>
                </ul>
                <div class="tab-content">
                    <div id="tab1" class="tab-pane active">
                        <neq name="info.id" value="1">
                            <div class="form-group">
                                <label class="item-label">上级部门<span class="check-tips">（所属的上级部门）</span></label>
                                <div class="controls">
                                    <select name="pid" class="form-control select">
                                        <volist name="all_group" id="group">
                                            <option value="{$group.id}"
                                                <php>if($group['id'] == $info['pid']) echo 'selected="selected"';</php> >
                                                {$group.title_show}
                                            </option>
                                        </volist>
                                    </select>
                                </div>
                            </div>
                        <else />
                            <div class="alert alert-success">{$info.title}拥有后台所有权限</div>
                        </neq>
                        <div class="form-group">
                            <label class="item-label">部门名称<span class="check-tips">（部门名称）</span></label>
                            <div class="controls">
                                <input type="text" class="form-control input" name="title" value="{$info.title|default=''}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="item-label">图标<span class="check-tips">（部门图标）</span></label>
                            <div class="controls">
                                <input type="text" class="form-control input icon" name="icon" value="{$info.icon|default=''}">
                                <script type="text/javascript">
                                    $(function(){
                                        $(".icon").iconChoosen({});
                                    });
                                </script>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="item-label">排序<span class="check-tips">（用于分组显示的顺序）</span></label>
                            <div class="controls">
                                <input type="text" class="form-control input" name="sort" value="{$info.sort|default=0}">
                            </div>
                        </div>
                    </div>
                    <neq name="info.id" value="1">
                        <div id="tab2" class="tab-pane">
                            <div class="container">
                                <div class="col-xs-12">
                                    <div class="form-group auth">
                                        <volist name="__ALL_MENU_LIST__" id="vo1">
                                            <div>
                                                <label class="checkbox">
                                                    <input type="checkbox" name="menu_auth[]" <php>if(in_array($vo1['id'], $info['menu_auth'])) echo "checked";</php> value="{$vo1.id}">{$vo1.title}
                                                </label>
                                                <div class="auth{$vo1.id}" style="padding-left: 25px;">
                                                    <volist name="vo1._child" id="vo2">
                                                        <label class="checkbox">
                                                            <input type="checkbox" name="menu_auth[]" <php>if(in_array($vo2['id'], $info['menu_auth'])) echo "checked";</php> value="{$vo2.id}">{$vo2.title}
                                                        </label>
                                                        <div class="auth{$vo2.id}" style="padding-left: 25px;">
                                                            <foreach name="vo2._child" item="vo3">
                                                                <label class="checkbox">
                                                                    <input type="checkbox" name="menu_auth[]" <php>if(in_array($vo3['id'], $info['menu_auth'])) echo "checked";</php> value="{$vo3.id}">{$vo3.title}
                                                                </label>
                                                                <notempty name="vo3._child">
                                                                    <div class="auth{$vo3.id}" style="padding-left: 25px;">
                                                                        <volist name="vo3._child" id="vo4">
                                                                            <notempty name="vo4._child">
                                                                                <div style="padding-top: 10px;">
                                                                                <label class="checkbox-inline">
                                                                                    <input type="checkbox" name="menu_auth[]" <php>if(in_array($vo4['id'], $info['menu_auth'])) echo "checked";</php> value="{$vo4.id}">{$vo4.title}
                                                                                </label>
                                                                                </div>
                                                                            <else />
                                                                                 <label class="checkbox-inline">
                                                                                    <input type="checkbox" name="menu_auth[]" <php>if(in_array($vo4['id'], $info['menu_auth'])) echo "checked";</php> value="{$vo4.id}">{$vo4.title}
                                                                                </label>
                                                                            </notempty>
                                                                            <notempty name="vo4._child">
                                                                                <div class="auth{$vo4.id}" style="padding-left: 25px;">
                                                                                    <foreach name="vo4._child" item="vo5">
                                                                                        <label class="checkbox-inline">
                                                                                            <input type="checkbox" name="menu_auth[]" <php>if(in_array($vo5['id'], $info['menu_auth'])) echo "checked";</php> value="{$vo5.id}">{$vo5.title}
                                                                                        </label>
                                                                                    </foreach>
                                                                                </div>
                                                                            </notempty>
                                                                        </volist>
                                                                    </div>
                                                                </notempty>
                                                            </foreach>
                                                        </div>
                                                    </volist>
                                                </div>
                                            </div>
                                        </volist>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </neq>
                    <neq name="info.id" value="1">
                        <div id="tab3" class="tab-pane">
                            <div class="row">
                                <volist name="category_auth_list" id="vo">
                                    <div class="col-xs 12 col-sm-3">
                                        <div class="panel panel-default " style="padding: 0px;">
                                            <div class="panel-heading">
                                                <h3 class="panel-title">{$vo.title}分组</h3>
                                            </div>
                                            <table class="table table-bordered table-responsive">
                                                <volist name="vo.auth" id="vo1">
                                                    <tr>
                                                        <td>
                                                            <label>
                                                                <input type="checkbox" name="category_auth[]" value="{$vo1.id}" <php>if(in_array($vo1['id'], $info['category_auth'])) echo "checked";</php>> {$vo1.title_show}
                                                            </label>
                                                        </td>
                                                    </tr>
                                                </volist>
                                            </table>
                                        </div>
                                    </div>
                                </volist>
                            </div>
                        </div>
                    </neq>
                </div>
                <div class="form-group">
                    <input type="hidden" name="id" value="{$info.id|default=''}">
                    <button class="btn btn-primary submit ajax-post" type="submit" target-form="form">确定</button>
                    <button class="btn btn-default return" onclick="javascript:history.back(-1);return false;">返回</button>
                </div>
            </form>
        </div>
    </div>
</block>

<block name="script">
    <script type="text/javascript">
        $(function(){
            //遍历选中当前权限的子权限
            $('.auth input[type="checkbox"]').on('change',function(){
                $('.auth'+$(this).val()).find('input').prop('checked',this.checked);
            });
        });
    </script>
</block>
